package com.ja.openchat.views;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.ja.openchat.R;
import com.lxj.xpopup.core.AttachPopupView;

import org.jetbrains.annotations.NotNull;

public class AttachCopyPopupView extends AttachPopupView {
    private String copyContent;

    public AttachCopyPopupView(@NonNull @NotNull Context context,String content) {
        super(context);
        copyContent = content;
    }

//    @Override
//    protected Drawable getPopupBackground() {
//        return ContextCompat.getDrawable(getContext(), R.drawable.transparent_shape);
//    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.popup_copy;
    }

    @Override
    protected void initPopupContent() {
        super.initPopupContent();
        findViewById(R.id.copy_btn).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                if (clipboardManager != null) {
                    ClipData clipData = ClipData.newPlainText("copyContent", copyContent);
                    clipboardManager.setPrimaryClip(clipData);
                    ToastUtils.showShort("已复制");
                }
                dismiss();
            }
        });
    }
}
